package com.hh.game.service.gateway.manager;

import com.hh.game.common.base.manager.session.Session;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SessionManager {
    private static Map<Integer , Session> onlineUserIdToSessionKeyMap = new ConcurrentHashMap<>();

    public static void onLine(int userId , Session session){
//        session.login();
        onlineUserIdToSessionKeyMap.put(userId ,session);
    }

    public static void offLine(int userId){
       onlineUserIdToSessionKeyMap.remove(userId);
    }

    public static Session getSession(int userId){
        return onlineUserIdToSessionKeyMap.get(userId);
    }

    public static boolean isOnLine(int userId){
        return onlineUserIdToSessionKeyMap.containsKey(userId);
    }

    public static Collection<Session> getAllOnLine(){
       return onlineUserIdToSessionKeyMap.values();
    }
}
